package com.example.demo.controller;

import com.example.demo.domain.Student;
import com.example.demo.service.StudentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/stu")
public class StudentController {

    @Autowired
    private StudentService service;

    @RequestMapping("/getAll")
    public List<Student> getAll(){
        System.out.println("进入方法--");
        List<Student> all = service.getAll();

        return all;
    }
    @RequestMapping("/findAll")
    public List<Student> findAll(){
        System.out.println("进入方法--");
        List<Student> all = service.findAll();

        return all;
    }

    @RequestMapping("/getOne")
    public Student getOne(@RequestParam(required = false,value = "id") String sid){
        System.out.println("进入方法--");
        return service.getOne(sid);
    }

    @RequestMapping("/getAll2")
    public List<Student> getAll2(){
        System.out.println("进入方法--");
        List<Student> all = service.getAll2();

        return all;
    }

    @PostMapping("/insertStu")
    public int insertStu(@RequestBody Student student){
        System.out.println(student.toString());
        System.out.println("进入方法--");
        int i = service.insertStu(student);

        return i;
    }

    @PostMapping("/insertStuList")
    public int insertStuList(@RequestBody List<Student> list ){
        list.forEach(student -> System.out.println(student.toString()));
        System.out.println("进入方法--");
        int i = service.insertStuList(list);

        return i;
    }

    @PostMapping("/deleteStu")
    public int deleteStu(@RequestParam String sid){
        System.out.println(service.getOne(sid).toString());
        System.out.println("进入方法--");
        int i = service.deleteStu(sid);
        return i;
    }

    @PostMapping("/deleteStuList")
    public int deleteStuList(@RequestParam Set<String> set){
        set.forEach(s -> System.out.println(s));
        System.out.println("进入方法--");
        int i = service.deleteStuList(set);
        return i;
    }

    @PostMapping("/updateStu")
    public int updateStu(@RequestBody Student student){
        System.out.println(student.toString());
        System.out.println("进入方法--");
        int i = service.updateStu(student);

        return i;
    }

}
